using System;
using LS.Saving;
using UnityEngine;
using Unity.VisualScripting;

namespace LS.VisualScripting
{
    public class GetAllFiles : SavingUnit
    {
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput GroupName { get; set; }
        
        [DoNotSerialize]
        public ValueOutput InfoArray { get; set; }
        
        [DoNotSerialize]
        public ValueOutput Count { get; set; }
        
        protected override void Definition()
        {
            base.Definition();
            GroupName = ValueInput<string>(nameof(GroupName), string.Empty);
            InfoArray = ValueOutput<IDataFile[]>(nameof(InfoArray));
            Count = ValueOutput<int>(nameof(Count));
            Requirement(GroupName, Input);
        }

        protected override ControlOutput In(Flow flow)
        {
            string groupName =  flow.GetValue<string>(GroupName);
            IDataFile[] info = Target?.GetAllFile(groupName)?? Array.Empty<IDataFile>();
            flow.SetValue(InfoArray, info);
            flow.SetValue(Count, info?.Length);
            return base.In(flow);
        }
    }
}